/*
 * @Author: 轻语
 * @Date: 2021-12-29 17:31:53
 * @LastEditors: 轻语
 * @LastEditTime: 2021-12-30 16:07:42
 * @Description: 
 */
const http = require('http');
const host = 'localhost';
const port = '8888';
const app = require('./router'); // 引入router.js文件

const server = http.createServer(app);
let str = '{"id":"1",name:"zhangSan",age:30,sex:"men"}';

app.post('/api/register', (req, res) => {
  res.write(`<head><meta charset="utf-8"/></head>`);
  res.end('注册接口响应')
});

app.post('/api/login', (req, res) => {
  res.write(`<head><meta charset="utf-8"/></head>`);
  res.end('登录接口响应')
});

app.get('/api/goods/list', (req, res) => {
  res.writeHead(200,{"Content-Type":'application/json','charset':'utf-8','Access-Control-Allow-Origin':'*','Access-Control-Allow-Methods':'PUT,POST,GET,DELETE,OPTIONS'});//可以解决跨域的请求
  //str=fs.readFileSync('json.txt');//读取文件内容
  res.write(str);
  res.end();
});
app.post('/api/goods/detail', (req, res) => {
  res.write(`<head><meta charset="utf-8"/></head>`);
  res.end('查询详情接口响应')
});

server.listen(port, host, () => {
  console.log(`Server running at http://${host}:${port}`);
});
